package com.flyme.module.file.client.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.flyme.common.core.model.base.AbstractEntity;
import com.flyme.common.core.security.OpenHelper;
import com.flyme.common.core.security.OpenUserAuth;
import com.flyme.common.core.utils.Md5Sign;
import com.flyme.common.core.utils.ObjectUtils;
import com.flyme.core.base.supper.EnumConvertInterceptor;
import com.flyme.core.base.supper.entity.EntityMap;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;

/**
 * 直播
 *
 * @author zyf
 * @date 2019-1-15
 */
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@TableName("sys_live")
public class SysLive extends AbstractEntity<SysLive> implements EnumConvertInterceptor {
    private static final long serialVersionUID = 1L;
    /**
     * 标题
     */
    private String liveTitle;
    /**
     * 封面图
     */
    private String liveImage;
    /**
     * 内容介绍
     */
    private String liveContent;
    /**
     * 直播状态0：未开始1：直播中2：已下架
     */
    private Integer liveStatus;
    /**
     * 讲师
     */
    private String lecturerId;
    /**
     * 直播时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm")
    private String liveTime;
    /**
     * 报名费
     */
    private BigDecimal regFee;
    /**
     * ios价格
     */
    private BigDecimal iosPrice;
    /**
     * 直播间ID
     */
    private Integer channelId;
    /**
     * 直播场景 alone 活动拍摄 ppt 三分屏 topclass 大班课
     */
    private String scene;
    /**
     * 排序
     */
    private Integer sortOrder;
    /**
     * 是否vip免费0:收费1：免费
     */
    private Integer isVipFree;

    @TableField(exist = false)
    private String liveUrl;


    @Override
    public boolean convert(EntityMap map, String key, Object v) {
        if (key.equals("channelId") && ObjectUtils.isNotEmpty(v)) {
            OpenUserAuth auth = OpenHelper.getUserAuth();
            String url = Md5Sign.getUrl(auth.getUserId(), Integer.parseInt(v.toString()));
            map.put("liveUrl", url);
        }
        return true;
    }
}
